import {Observer} from "@/utils/observer/Observer";
import {UserWaitApi} from "@/api/user_api";

/**
 * 呼叫记录 -- 内置呼叫记录
 */
class WaitEmbedCallingPatientRecordsObserverBiz extends Observer{
  constructor(self, deviceInfo = {}, item) {
    super();
    // 外部组件
    this.catcheInfo = self;
    // 设备信息
    this.deviceInfo = deviceInfo;
    // 当前组件信息
    this.currentInfo = item || {};
  }

 async init() {
   await this.getPatientLog()
 }
  /**
   * 消息监听入口
   * @param bizType
   * @param msgContent
   */
  async update(bizType, msgContent) {
    let self = this.catcheInfo;
    try {
      switch (bizType) {
        case "refreshMsg":
          await this.refreshMsg(msgContent);
          break;
      }
    } catch (e) {
      console.error("消息数据加载失败：" + msgContent)
      self.handleException("sdkBizServices", "安卓消息消费异常 -- " + bizType + " -- >", JSON.stringify(e.stack));
    }
  }

  /**
   * 刷新消息
   * @param str
   * @returns {Promise<void>}
   */
  async refreshMsg(str) {
    await this.getPatientLog();
  }

  /**
   * 获取呼叫记录
   */
  async getPatientLog() {
    // 重置排班
    let self = this.catcheInfo;
    try {
      const {data,code} = await UserWaitApi.getPatientLog({
        statusList: ["CALL_NEXT","CALL_SELECT"],
        registerObjIdList: [],
        pageSize: self.waitingScreenWaitingData.embedCallingPatientConfig.pageSize,
        pageNum: self.waitingScreenWaitingData.embedCallingPatientConfig.pageNum,
        onlineStatus:true == this.recordsLine?'0':'',
        orderByColumn: "operation_time",
        isAsc:'',// 排序的方向desc或者asc
        terminalId: self.deviceInfo.screenId,
        terminalType: self.deviceInfo.screenType,
        businessType: self.deviceInfo.businessType,
        tenantId: self.deviceInfo.hospitalId
      })
      if(code == 200){
        // 给组件发送数据
        this.waitingSetDataList(data.rows || []);
      }else{
        // 给组件发送数据
        this.waitingSetDataList([]);
      }
    }catch (e) {
      self.handleWriteLog('sdkServices',  "MtUserGetPatientLog --> 获取呼叫记录错误"+ JSON.stringify(e.stack));
    }
  }

  /**
   * 给组件写数据
   * @param data
   */
  waitingSetDataList(data){
    let self = this.catcheInfo;
    try {
      const formRef = self.$refs['vFormRef'];
      if (formRef) {
        formRef.executeChildMethod(this.currentInfo?.id, 'patientRecordsListInfo', data);
      }
    }catch (e) {
      self.handleException('sdkBizServices', '内部组件异常 --呼叫记录设置-- waitingSetDataList -- >', JSON.stringify(e.stack));
    }
  }

}

export {WaitEmbedCallingPatientRecordsObserverBiz};
